package org.kazuhiko.pokemon3d.utility.tools;

import java.awt.Font;
import java.awt.Color;

import org.newdawn.slick.SlickException;
import org.newdawn.slick.UnicodeFont;
import org.newdawn.slick.font.effects.ColorEffect;

public class TextRenderer
{
	private static TextRenderer instance;
	
	private UnicodeFont font;
	private Font awtFont;
	
	public static TextRenderer getRenderer()
	{
		if( instance == null )
		{
			instance = new TextRenderer();
		}
		
		return instance;
	}
	
	private TextRenderer()
	{		
		loadFont( "Arial", Font.PLAIN, 12, Color.white );
	}
	
	public void render2DText( String text, float x, float y )
	{
		font.drawString( x, y, text );
	}
	
	public void render2DText( String text, org.newdawn.slick.Color color, float x, float y )
	{
		font.drawString( x, y, text, color );
	}
	
	public void render2DText( String text, Color color, float x, float y, int size )
	{
		loadFont( "Verdana", Font.PLAIN, size, color );
		font.drawString( x, y, text );
	}
	
	@SuppressWarnings("unchecked")
	public void loadFont( String family, int weight, int size, Color color )
	{
		System.out.println( "Loading " + family + " font." );
		awtFont = new Font( family, weight, size );
		font = new UnicodeFont( awtFont );
		font.getEffects().add( new ColorEffect( color ) );
		font.addAsciiGlyphs();
		try
		{
			font.loadGlyphs();
		}
		catch( SlickException e )
		{
			e.printStackTrace();
		}
	}
}
